import 'package:amway_superapp_creator_plugin/config/colors_config.dart';
import 'package:amway_superapp_creator_plugin/routers/application.dart';
import 'package:amway_superapp_creator_plugin/routers/routes.dart';
import 'package:amway_superapp_creator_plugin/utils/toast_util.dart';
import 'package:amway_superapp_creator_plugin/viewmodels/create_splash_viewmodel.dart';
import 'package:amway_superapp_creator_plugin/views/base_view.dart';
import 'package:amway_superapp_creator_plugin/widget/back_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';

import '../routers/application.dart';
import '../view_state.dart';

class CreateSplashView extends StatelessWidget {
  var amwayAda;
  var amwayId;
  var phone;

  CreateSplashView({this.amwayAda, this.amwayId, this.phone});

  @override
  Widget build(BuildContext context) {
    return BaseView(
      model: CreateSplashViewModel(api: Provider.of(context)),
      onModelReady: (model) {
        model.queryprivacyLink();
      },
      builder: (context, model, child) =>
      model.state == ViewState.Idle ? Scaffold(
        appBar: AppBar(
          backgroundColor: ColorsConfig.c_F0FAE5,
          elevation: 0,
          leading: BackButtion(
            onTap: () {
              Application.router.pop(context);
            },

          ),
        ),
        body: SingleChildScrollView(
            child: Stack(
              children: [
                Container(
                  child: Image.asset(
                    "picture/image_splash.png",
                    package: 'amway_superapp_creator_plugin',
                  ),
                ),
                Positioned(
                  bottom: 0,
                  left: 0,
                  right: 0,
                  child: Container(
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [
                        Text(
                          '点击下方按钮，即刻开启创玩小站吧！',
                          style: TextStyle(
                              fontSize: ScreenUtil().setSp(20),
                              color: Colors.black),
                        ),
                        Icon(
                          Icons.keyboard_arrow_down_outlined,
                          size: 20,
                          color: Colors.black,
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            )),
        bottomNavigationBar: buildeBottom(context, model),
      ) : Container(
        color: Colors.white,
        child: Center(
          child: CircularProgressIndicator(),
        ),
      ),
    );
  }

  TextStyle style =
  TextStyle(fontSize: ScreenUtil().setSp(14), color: ColorsConfig.c_2c2c2c);

  Widget buildeBottom(BuildContext context, CreateSplashViewModel model) {
    return Container(
      color: Colors.white,
      height: ScreenUtil().setHeight(122),
      child: Column(
        children: [
          Container(
            margin: EdgeInsets.only(top: ScreenUtil().setHeight(10)),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                Text("点击按钮表示我已阅读并同意", style: style),
                InkWell(
                  onTap: () {
                    if (null == model.privacyLink) {
                      ToastUtils.showShortToast("后台可能还没有链接地址哟");
                      return;
                    }
                    Map<String, dynamic> map = {};
                    map['url'] = model.privacyLink;
                    Application.router.navigateTo(context, Routes.openWebView,
                        routeSettings: RouteSettings(arguments: map));
                  },
                  child: Text(
                    "《隐私政策》",
                    style: TextStyle(
                        fontSize: ScreenUtil().setSp(14),
                        color: ColorsConfig.c_396E75),
                  ),
                ),
                Text(
                  "的所有内容",
                  style: style,
                ),
              ],
            ),
          ),
          Container(
            width: double.infinity,
            margin: EdgeInsets.only(
                left: ScreenUtil().setWidth(20),
                top: ScreenUtil().setHeight(10),
                right: ScreenUtil().setWidth(20)),
            child: FlatButton(
              padding:
              EdgeInsets.symmetric(vertical: ScreenUtil().setHeight(12)),
              splashColor: Colors.transparent,
              child: Text(
                "开启创玩小站",
                style: TextStyle(
                    color: Colors.white, fontSize: ScreenUtil().setSp(18)),
              ),
              onPressed: () {
                Application.router.pop(context);
                Map<String, dynamic> parameters = {
                  'amwayAda': amwayAda,
                  'amwayId': amwayId,
                  'phone': phone,
                };
                Application.router.navigateTo(
                  context,
                  Routes.root,
                  routeSettings: RouteSettings(arguments: parameters),
                );
              },
              shape: StadiumBorder(),
              color: ColorsConfig.c_396E75,
              disabledColor: ColorsConfig.c_396E75,
            ),
          )
        ],
      ),
    );
  }
}
